<%- include header %>
<!-- page content -->
<div class="right_col" role="main">

    <div class="">
        <div class="page-title">
        </div>
        <div class="clearfix"></div>

        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
            	<div class="x_panel">
                    <div class="x_title">
                        <ul class="breadcrumb">
                            <li>
                                <a href="/admin/index">
                                    <i class="fa fa-home"></i>&nbsp;首页&nbsp;&nbsp;
                                </a>
                            </li>
                            <li class="active">
                                <i class="fa fa-shopping-bag"></i>&nbsp;商品管理
                            </li>
                            <li class="active">
                            	商品搜索结果
                            </li>
                        </ul>
                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">
                        <!-- start project list -->
                        <table class="table table-striped responsive-utilities jambo_table bulk_action">
                            <thead>
                                <tr>
                                    <th>排序</th>
                                    <th>商品名称</th>
                                    <th>商品属性</th>
                                    <th>商品封面</th>
                                    <th>商品类别</th>
                                    <th>规格</th>
                                    <th>创建时间</th>
                                    <th style="min-width: 80px;">操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                    <% if(goodses){%>
                                    <% if(goodses.length>0){ var i =0;%>
                                    <% goodses.forEach(function(goods){ %>
                                    <% i++ %>
                                    <tr name="tr_<%= goods._id %>">
                                    <td><%= goods.indexNum %></td>
                                    <td><%= goods.title %></td>
                                    <td><% var map=['推荐(每日精选)','新品(猜你喜欢)','热卖','包邮','不参与会员折扣'] %><%= map[goods.goodsStyle] %></td>
                                    <td>
                                        <img style="width:68px;height:68px;"  src="<%= goods.thumbnailUrl  %>"/>
                                    </td>
                                    <td><%= goods.goodsCategoryName %></td>
                                    <td>
                                    	<ul class="list-inline">
                                    		<% var map2 =['通用','线上','线下'] %>
                                    		<% for (var i = 0; i < goods.specification.length; i++) { %>
                                            	<li>
                                            		[<%= map2[goods.specification[i].onlineState] %>]<%= goods.specification[i].price %>元/<%= goods.specification[i].specificationName %>
                                            	</li>
                                            	</br>
                                            <% } %>
                                        </ul>
                                    </td>
                                    <td><% var date = new Date(goods.createTime);var d = date.getDate();if(d<10){d = '0'+d;}var m = date.getMonth()+1;if(m<10){m = '0'+m;}var y = date.getFullYear();var h = date.getHours();if(h<10){h = '0'+h;}var min = date.getMinutes();if(min<10){min = '0'+min;}var d1 =  y+'-'+m + '-' + d;%><%= d1 %></td>
                                    <td>
                                        <div class="btn-group">
                                            <a title="编辑" href="/admin/goods/edit?goods_id=<%= goods._id %>" class="btn btn-default btn-xs"><i class="fa fa-pencil"></i>&nbsp;编辑</a>
                                            <a title="删除" onclick="del('<%= goods._id %>')" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i>&nbsp;下架</a>
                                        </div>
                                    </td>
                                    </tr>
                                    <% }) %>
                                    <% }} %>
                            </tbody>
                        </table>
                        <!-- end project list -->

                        </br>
                        <% if(goodses){ %>
                        <% thisPage=parseInt(thisPage);var total = total;var pages = Math.ceil(total/10);var page_f = 1; var page_p = thisPage-1;var page_n = thisPage+1;var page_l = Math.ceil(total/10);%>
                        <div class="dataTables_paginate paging_full_numbers" id="example_paginate">
                            <% if(thisPage<=1){ %>
                            <a tabindex="0" class="first paginate_button paginate_button_disabled" id="example_first">首页</a>
                            <% }else{ %>
                            <a tabindex="0" class="first paginate_button paginate_button" id="example_first" href="/admin/tools/search?page=1">首页</a>
                            <% } %>
                            <% if(thisPage<=1){ %>
                            <a tabindex="0" class="previous paginate_button paginate_button_disabled" id="example_previous">上一页</a>
                            <% }else{ %>
                            <a tabindex="0" class="previous paginate_button paginate_button" id="example_previous" href="/admin/tools/search?page=<%= page_p %>">上一页</a>
                            <% } %>
                            <span>
                                <%var n1 = pages;%>
                                <% if(n1<5){ %>
                                    <% for(var i=1;i<=n1;i++){ %>
                                        <% if(i==thisPage){ %>
                                        <a tabindex="0" class="paginate_active" href="/admin/tools/search?page=<%= i %>"><%= i %></a>
                                        <% }else{ %>
                                        <a tabindex="0" class="paginate_button" href="/admin/tools/search?page=<%= i %>"><%= i %></a>
                                        <% } %>
                                    <% } %>
                                <% }else{ %>
                                    <% for(var i=1;i<=5;i++){ %>
                                        <% if(i==thisPage){ %>
                                        <a tabindex="0" class="paginate_active" href="/admin/tools/search?page=<%= i %>"><%= i %></a>
                                        <% }else{ %>
                                        <a tabindex="0" class="paginate_button" href="/admin/tools/search?page=<%= i %>"><%= i %></a>
                                        <% } %>
                                    <% } %>
                                    <a tabindex="0" class="paginate_button">...</a>
                                    <% if(page_l==thisPage){ %>
                                        <a tabindex="0" class="paginate_active" href="/admin/tools/search?page=<%= page_l %>"><%= page_l %></a>
                                    <% }else{ %>
                                        <a tabindex="0" class="paginate_button" href="/admin/tools/search?page=<%= page_l %>"><%= page_l %></a>
                                    <% } %>
                                <% } %>
                            </span>
                            <% if(page_n>pages){ %>
                            <a tabindex="0" class="next paginate_button_disabled" id="example_next">下一页</a>
                            <% }else{ %>
                            <a tabindex="0" class="next paginate_button" id="example_next" href="/admin/tools/search?page=<%= page_n %>">下一页</a>
                            <% } %>
                            <% if(page_l==thisPage){ %>
                            <a tabindex="0" class="last paginate_button_disabled" id="example_last">尾页</a>
                            <% }else{ %>
                            <a tabindex="0" class="last paginate_button" id="example_last" href="/admin/tools/search?page=<%= page_l %>">尾页</a>
                            <% } %>
                        </div>
                        <% } %>
                    </div>
                </div> 
            </div>
        </div>
    </div>
    <div class="modal fade bs-example-modal-lg2" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-body" id="ex1">
                    <img src="" style="width: 100%" />
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>
</div>
<%- include bottom %>
<script src="/js/zoom/jquery.zoom.js"></script>
<script type="text/javascript">
	function show(url){
        $('#ex1 >img').attr('src',url);
        $('#ex1').zoom();
    }
    function del(id) {
        var postData = {goods_id: id};
        if (confirm("真的要下架这个商品吗？")) {
            $.ajax({
                type: 'post',
                url: '/admin/goods/del',
                data: postData,
                dataType: 'json',
                success: function(data) {
                    if(!data.status) {
                        return alert(data.message);
                    }
                    $('tr[name="tr_'+id+'"]').remove();
                }
            })
        }
    }
</script>
<%- include footer %>